package com.zye.servlet;

import com.zye.JDBCUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/delete")

public class deleteStudent extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        int id = Integer.parseInt(req.getParameter("id"));
        int rows = JDBCUtils.update("delete from student where id=?",id);
        if(rows>0){
            System.out.println("删除成功");
            resp.getWriter().write("删除成功");
        }
        else{
            System.out.println("删除失败");
            resp.getWriter().write("删除失败");
        }
    }
}
